var do_App = sm("do_App");
var do_Page = sm("do_Page");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var deviceone = require("deviceone");
var userUrl = require("url/user");
var httpSilence = require("helper/httpSilence");
var openHelper = require("helper/open");
// UI
var headerAout = ui("headerAout");
var linearLayout_main = ui("linearLayout_main")

// 加载头部
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
// andriod返回键
do_Page.on("back", function() {
	do_App.closePage();
});
// 左上角-返回
var headerLeft = ui(addheader + ".headerLeft");
// 右上角-
var headerRight = ui(addheader + ".headerRight");
headerRight.visible = false;
headerLeft.on("touch", function() {
	do_App.closePage()
});
var header = ui("header");
header.bindData(hashdata);
hashdata.addData({
	"labelTitle" : "隐私设置",
})
header.refreshData();

/**
 * ********************************************************switch
 */
var switchtxt = linearLayout_main.add("txtswitch","source://view/reuse/form/mutiSwitch.ui");
var switchtxtS = ui("txtswitch");
var labelTitle = ui(switchtxt + ".labelTitle");
var aLayoutRoot = ui(switchtxt + ".aLayoutRoot");
aLayoutRoot.tag=1;
switchtxtS.bindData(hashdata);
hashdata.addData({
	"labelTitle" : "是否被社区邻里发现"
})
switchtxtS.refreshData();
var swtxt = [ 1, " ", " " ]; // 0:开关状态 1:关闭状态文字 2:开启状态文字

switchtxtS.on("switchtag", function(data) {
	if (data == 0) {// 关闭，不允许别人查看
		add(aLayoutRoot.tag);
	}
	if (data == 1) {// 打开，允许别人查看、默认是打开
		del(labelTitle.tag);
	}
});
switchtxtS.fire("switchzt", swtxt);
/************圈子隐私*************/
var addCircleSecretSt = linearLayout_main.add("circleSecretSt", "source://view/reuse/mutiLabel.ui","txtswitch");
var circleSecretSt = ui("circleSecretSt");
circleSecretSt.bindData(hashdata);
hashdata.addData({
	"imgLeft" : "source://image/setting/setting.png",
    "labelTitle" : "隐藏我的圈子",
    "labelTipsVisible":true,
    "labelTips":"保护自己的圈子隐私信息"
});
circleSecretSt.refreshData();
ui(addCircleSecretSt).on("touch", function(data, e) {
	openHelper.open("source://view/user/privacy/circleSet/circleSet.ui");
});
/*************************/
//页面装载完成后，开始初始化工作
do_Page.on("loaded", function(){
	loadPage();
});

function loadPage() {
	httpSilence.post(userUrl.url.privacy.get, {}, function(data) {
		if (null != data.cNeighborVo) {
			labelTitle.tag = data.cNeighborVo.id;
			aLayoutRoot.tag = data.cNeighborVo.type;
			var swtxt = [ 0, " ", " " ]; // 0:开关状态 1:关闭状态文字 2:开启状态文字
			switchtxtS.fire("switchzt", swtxt);
		}
	})
}
function add(type) {
	httpSilence.post(userUrl.url.privacy.create, {
		type : type,
	}, function(data) {
		if (null != data.userPrivacyVo) {
			labelTitle.tag = data.userPrivacyVo.id;
			aLayoutRoot.tag = data.userPrivacyVo.type;
		}
	})
}
function del(id) {
	httpSilence.post(userUrl.url.privacy.del, {
		id : id
	}, function(data) {
	})
}
